﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;

public partial class System_CodeGroupNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] == null)
            {
                ActionTitle.Text = "添加编码组";
            }
            else
            {
                ActionTitle.Text = "编辑编码组";
                BindData();
                GroupID.ReadOnly = true;
            }
        }
    }
    private void BindData()
    {
        CodeGroupInfo info = CodeGroup.GetDetail(Request.QueryString["id"]);
        GroupID.Text = info.GroupID;
        GroupName.Text = info.GroupName;

    }
    private void Insert()
    {
        if (CodeGroup.Exists(GroupID.Text))
        {
            Prompt.Text = "警告：该编码组已存在！";
            return;
        }
        CodeGroupInfo info = new CodeGroupInfo() { GroupID = GroupID.Text, GroupName = GroupName.Text };
        if (CodeGroup.Insert(info))
            Prompt.Text = "提示：添加成功！";
        else
            Prompt.Text = "提示：添加失败！";
    }
    private void Update()
    {
        CodeGroupInfo info = CodeGroup.GetDetail(Request.QueryString["id"]);
        info.GroupName = GroupName.Text;
        CodeGroup.Update(info);
        Prompt.Text = "提示：更新成功！";
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["ID"] == null)
            Insert();
        else
            Update();
    }
}
